define([], function(require, factory) {
    'use strict';

    function Router(config){
        this.config = config || [];
        this.init();
    }

    Router.prototype.setPage = function(){
        var currentHash = window.location.hash;
        currentHash = /^\#/.test(currentHash) ? currentHash.substring(1) : currentHash;
        console.log('currentHash', currentHash);
        this.config.forEach(function(item){
            if(currentHash == item.path){
                var components = item.component();
                document.getElementById("router-view").innerHTML = components.htmlStr;
                components.render();
            }
        })
    }

    Router.prototype.init = function(){
        this.setPage();
        this.setListener();
    }

    Router.prototype.setListener = function(){
        var that = this;
        if('onhashchange' in window){
            window.onhashchange = function(e){
                console.log('hashChange', e);
                that.setPage();
            }
        }else{
            console.log("当前浏览器不支持hash");
        }
    }

    return Router;
});